package com.hmall.search.web;

import com.hmall.common.dto.PageDTO;
import com.hmall.search.pojo.ItemDoc;
import com.hmall.search.pojo.RequestParams;
import com.hmall.search.service.ISearchService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author www
 * @Description SearchController层
 * @Date 2023/4/11 12:38
 * @Version 1.0
 */
@RestController
@RequestMapping("search")
public class SearchController {
    /**
     * 注入ISearchService
     */
    @Resource
    private ISearchService searchService;

    /**
     * 根据用户请求值 自动补全
     * @param prefix 用户请求值
     * @return 返回数据
     */
    @GetMapping("/suggestion")
    public List<String> getSuggestion(@RequestParam("key") String prefix) {
        return searchService.getSuggestion(prefix);
    }

    /**
     * 过滤项聚合
     * @param params 用户请求参数
     * @return 返回数据
     */
    @PostMapping("/filters")
    public Map<String,List<String>> getFilters(@RequestBody RequestParams params){
        return searchService.getFilters(params);
    }

    /**
     * 分页查询
     * @param params 用户请求参数
     * @return 返回数据
     */
    @PostMapping("/list")
    public PageDTO<ItemDoc> search(@RequestBody RequestParams params){
        return searchService.search(params);
    }
}

